<template>
	<view class="contont" style="background-color: #F5F5F5;">
		<view class="infromid">
			<view style="height: 50%;width: 100%;border-bottom: 1px solid #F5F5F5;" class="cent" >
					<text style="font-size: 15px;margin-left: 30rpx;">姓名</text>
					<input type="text"  placeholder="请输入个人姓名" v-model="code"  style="font-size: 15px;width: 30%;margin-right: 15px;text-align: right;"/>
			</view>
			<view style="height: 50%;width: 100%; " class="cent" >
					<text style="font-size: 15px;margin-left: 30rpx;">身份证号</text>
					<input type="text"  placeholder="请输入个人身份证号" maxlength="18" v-model="codes"  style="font-size: 15px;width: 50%;margin-right: 15px;text-align: right;"/>
			</view>
		</view>
		<view class="infromeid">
			<view class="cents" style="height: 50%;width: 100%;">
					<text style="height: 100%;margin-left: 30rpx;padding-top: 32px;">驾驶证照片</text>
					<view class="" style="width: 240px;height: 120px;">
						<image src="../../static/img/img_shangchuanxiao@2x.png" mode="" style="width: 100%;height: 100%;overflow: hidden;"  @click="img" v-if="imaged.length==0"></image>
				<image :src="imaged[0]" mode="" style="width: 240px;height: 120px;"  v-if="imaged.length!=0"  @click="img"></image>
					</view>
				
			</view>
			<view class="cents" style="height: 50%;width: 100%;">
					<text style="height: 100%;margin-left: 30rpx;padding-top: 32px;">驾驶证照片</text>
					<image src="../../static/img/img_shangchuan@2x.png" mode="" style="width: 240px;height: 120px;"></image>
			</view>
		</view>
		<button @click="but" style="margin-top: 20px;">提交</button>

	</view>
</template>

<script>
	import {ajax} from '../../api.js'
	export default {
		data() {
			return {
				imaged:[],
				codes:"",
				code:"",
				list:[],
				phone:""
			}
		},
		onLoad(option) {
			
		var that=this
		this.code=option.username
		this.codes=option.idnumber
		ajax({
			url:"/v1/appdriver/user/profile",
			success(res){
				
				that.list=res.data.message
			}
		})
		},
		methods: {
	
			img(){
				
 var  _self = this;
	  wx.showActionSheet({
	       itemList: ['拍照','从手机相册选择'],
	    success(res) {
	   
	      if(res.tapIndex==0){ //0是拍照
	        wx.chooseImage({
	          count: 1,
	          sizeType: ['compressed'],
	          sourceType: ['camera'],
	          success: function (res) {
	             _self.imaged= res.tempFilePaths;
	           },
	        })
	      } else if(res.tapIndex==1){
	        wx.chooseImage({
	          count: 1,
	          sizeType: ['compressed'],
	          sourceType: ['album'],
	          success: function(res) {
	          _self.imaged= res.tempFilePaths;
	          },
	        })
	      }
	    }
	  })
				 },
				
				but(){
					var _self=this
					if(this.imaged.length==0){
						uni.showToast({
						    title:'请选择行驶证',
							icon:"none"
						})
						}else if(this.code!=""){
						uni.getStorage({
							key:"name",
							success:function(res){
								
								 _self.phone=res.data.phone
						var header;
														  header = { 
											
											     'content-type': 'multipart/form-data', 
											
											     'cookie':uni.getStorageSync("sessionid")//读取cookie
											
											  };
						const uploadTask = uni.uploadFile({
						 url : 'https://www.uhuoda.com/v1/appdriver/user/editprofile',
						 filePath: _self.imaged[0],
						 name: 'driverLicensePhoto',
						 header:header,
						 formData: {
									phone:res.data.phone,
						  			username:_self.code,
						  			idnumber:_self.codes,
						  			
						 },
						 success (uploadFileRes) {
						
							if(JSON.parse(uploadFileRes.data).status=="OK"){
							uni.navigateBack({
								delta:1
							})
							}else{
								uni.showToast({
								    title: JSON.parse(uploadFileRes.data).message,
									icon:"none"
								})
							}
						 
						 }
						});
										 
							},
						})
					}else{
						uni.showToast({
						    title: '请输入正确身份证',
							icon:"none"
						})
					}
				}
		},
	}
</script>

<style>
	page{
		height: 100%;
	}
.infromid{
	width:355px;
	height:111px;
	background:rgba(255,255,255,1);
	border-radius:8px;
	margin-top: 10px;
}
 .infromeid{
	width:355px;
	height:285px;
	background:rgba(255,255,255,1);
	border-radius:8px;
	margin-top: 10px;
}
button{
	width:355px;
	height:44px;
	background:rgba(4,42,88,1);
	border-radius:8px;
	color: #FFFFFF;
}

</style>
